/*
 * BlackLightning.GameServer
 * Andy Tidball
 * 
 * Project: Black Lightning
 * Copyright: GNU General Public License
 */

using System;
using BlackLightning.PluginLib.LoginClients;
using BlackLightning.PluginLib.Modules;
using BLLib.Net;

namespace BlackLightning {
	/// <summary>
	/// Encapsulates a connection to the game server.
	/// </summary>
	internal class GameServer : PacketConnection {
		/// <summary>
		/// Creates a derived instance of GameServer appropriate for the given SAL file.
		/// </summary>
		/// <param name="SAL">An SalFile as returned by the login server.</param>
		/// <param name="C">A Connection which is already connected to the game server.</param>
		/// <param name="FirstConnection">True if this is the first time connecting to a game server this run.</param>
		/// <returns>A new instance of a type of GameServer appropriate for the SalFile.</returns>
		public static GameServer Create(SalFile SAL, Connection C, bool FirstConnection) {
			switch (SAL.ClientCode) {
				case "STORM": return new SFGameServer(C, FirstConnection);
				case "WIZ":   return new GSLGameServer(C, FirstConnection);
				default:      throw new InvalidOperationException("Unknown client code in given SAL file.");
			}
		}

		/// <summary>
		/// Creates a new GameServer.
		/// </summary>
		/// <param name="Connection">An already connected and handshaked connection to the game server.</param>
		/// <param name="PacketTerminator">The string which signals the end of a packet.</param>
		/// <param name="AppendTerminator">Whether or not to append the packet terminator to outgoing packets that don't already end with it.</param>
		/// <param name="SendNewLine">The string that the other end of the connection recognizes as a new line when we're sending to it.</param>
		/// <param name="ReceiveNewLine">The string that the other end of the connection recognizes as a new line when we're receiving from it.</param>
		public GameServer(Connection Connection, string PacketTerminator, bool AppendTerminator, string SendNewLine, string ReceiveNewLine)
			: base(Connection, PacketTerminator, AppendTerminator, SendNewLine, ReceiveNewLine) {
		}
	}
}
